<?php

namespace App\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

class Message extends Model
{
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:i');
    }

    public function scopeCreatedAt($query)
    {
        return $query->where('created_at', '>', Carbon::parse('-6 month')->toDateTimeString());
    }

    public function scopeCompanyId($query)
    {
        return $query->where('company_id', company_id());
    }

    public function scopeUserId($query)
    {
        return $query->where('user_id', user_id());
    }
}
